package com.source.multithread.run;

import lombok.SneakyThrows;

/**
 * @Author wengqy
 * @Date 2020/12/19
 */
public class YieldDemo   {

    public static void main(String[] args) throws InterruptedException {
           Train  train = new Train();
           Thread k5566 = new Thread(train, "K5566");
           Thread g217 = new Thread(train, "G217");

           k5566.start();
         //  Thread.sleep(100);
        g217.start();
   //     g217.join();



        for (int i = 0; i <200 ; i++) {
            if(i==0){
                System.out.println(Thread.currentThread().getName());
                g217.join();
            }
        }





    }


}


class Train implements  Runnable{

    public boolean isRun=true;
    public static int num=100;
    @Override
    public void run() {
     while(num>0){
         try {
             Thread.sleep(100);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
         System.out.println(Thread.currentThread().getName()+"-----------"+num--);
         /*for (int i = 0; i <100 ; i++) {
             try {
                 Thread.sleep(100);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             System.out.println(Thread.currentThread().getName());
         }*/
     }




    }
}